home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / comt010d.zip / COMTSRC.ZIP / UULDR.ASM < prev   
Assembly Source File  |  1991-12-26  |  2KB  |  102 lines

  1. ; implement a sort-of UUdecoder
  2. ;
  3.  
  4. include enc.inc
  5.  
  6. CodeTop = 34
  7. Begin   = '<'
  8.  
  9. .model tiny
  10. .code
  11. org 100h
  12. Origin=EncLoadedAt-100h
  13. Top:
  14.   cld
  15.   push cs
  16.   pop es
  17.   push di         ; save place where AB has finished and UU is coming [*]
  18.   lea di,[bp+63h] ; and here is the input pointer
  19.   mov al,Begin    ; look for a <
  20.   mov cx,12000    ; over the next 12000 bytes
  21.   repnz scasb
  22.   jnz Error       ; Not found???
  23.   mov si,di       ; Set source pointer to AFTER the said <
  24.   pop di          ; restore the place where UU decoding will happen
  25.   push di         ; and save it for later
  26.  
  27. DecTop:
  28.   lodsb
  29.   cmp al,CodeTop-1
  30.   jz Decoded
  31.   sub al,CodeTop
  32.   jb DecTop  ; Skip what we do not understand
  33.   cmp al,64
  34.   jae DecTop
  35.   mov ah,al
  36.   lodsb
  37.   sub al,CodeTop
  38.   rcr ah,1   ; carry clear
  39.   rcl al,1
  40.   rcr ah,1
  41.   rcl al,1   ; Whee!  al is now right for byte 1
  42.   stosb
  43.   lodsb
  44.   sub al,CodeTop
  45.   rcr ah,1
  46.   rcl al,1
  47.   rcr ah,1
  48.   rcl al,1   ; Whee!  al is now right for byte 2
  49.   stosb
  50.   lodsb
  51.   sub al,CodeTop
  52.   rcr ah,1
  53.   rcl al,1
  54.   rcr ah,1
  55.   rcl al,1   ; Whee!  al is now right for byte 3
  56.   stosb
  57.   jmp DecTop
  58.  
  59. Error:
  60.   mov ax,4cffh
  61.   int 21h
  62.  
  63. Decoded:
  64. ; Great!  We have now finished decoding
  65.  
  66.   push di         ; di points after the decoding
  67.                   ; this space is free since it was filled before
  68.                   ; with the encoded original
  69. ; Append the loader
  70.   mov si,offset BegMoveData+Origin
  71.   mov cx,offset EndMoveData-offset BegMoveData
  72.   rep movsb
  73.   pop di          ; restore di to end of decoded data
  74.   jmp di
  75.  
  76. ; This stuff now had better be relocatable.  On entry di points to its
  77. ; head.
  78. BegMoveData:
  79. ; Copy the (now) decoded programme to ds:100=cs:100=es:100
  80.   mov cx,di   ; cx=end of decoded data
  81.   pop si      ; si=start of decoded data from [*]
  82.   sub cx,si   ; length of decoded program
  83.   inc cx
  84.   shr cx,1    ; cx>=2*Length of decoded program
  85.   mov di,100h
  86.   rep movsw
  87.  
  88.   mov ax,100h
  89.   push ax
  90.   xor ax,ax  ; I am sure some are not needed, so I commented them out
  91.   mov bx,ax
  92.   mov cx,ax
  93.   mov dx,ax
  94.   mov si,ax
  95.   mov di,ax
  96.   mov bp,ax
  97.   ret         ; jump to 100h
  98. EndMoveData:
  99.  
  100. end Top  ; to fool tlink into making a .com file which we rename to .bin
  101.  
  102.